﻿using HelloASPNET.TruyXuatDuLieu;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HelloASPNET.Test
{
  public partial class DemoDataBinding : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      //1) Gán datasource cho các control
      //int[] mangSo = new int[]{1,2,3,4,5,6,7};

      //DropDownList1.DataSource = mangSo;

      //ListBox1.DataSource = mangSo;

      ////2) Yeu cau binding bang cach goi phuong thuc DataBind( ) cua control
      ////DropDownList1.DataBind();

      //mangSo[0] = 50;
      ////ListBox1.DataBind();
      //this.DataBind();
      //=======================
      DataTable tblNguoiDung = TienIchSQL.ChayLenhSelectDuLieu("SELECT * FROM NguoiDung");
      DropDownList1.DataSource = tblNguoiDung;
      DropDownList1.DataTextField = "HoTen"; //Ten column se hien thi
      DropDownList1.DataValueField = "username";// ten column su duoc dung lam value

      ListBox1.DataSource = tblNguoiDung;
      ListBox1.DataTextField = "Username";

      GridView1.DataSource = tblNguoiDung;

      DropDownList1.DataBind();
      ListBox1.DataBind();
      GridView1.DataBind();
    }
  }
}